<?php
/* 
*    This program is free software: you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation, either version 3 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
*/
include ("Mirrorbow.class.php");

$mb_device = new Mirrorbow();
#$mb_device->setDebug(true);

#YOU can use as many devices as you like
$mb_device->mirrorbow_device = array("myfirst" => "80.42.206.220", "livingroom" => "192.168.1.68");

$values = $mb_device->getDeviceDetails("livingroom");
/*
AVAILABLE INDEXES OF THE RESULT ARRAY:
 * see http://mirrorbowio/ports.xml for more details
    [port1]
    [port2]
    [port3]
    [port4]
    [port5]
    [port6]
    [adc1]
    [adc2]
    [adc3]
    [adc4]
    [adc5]
    [adc6]
    [adc7]
    [adc8]
    [adc9]
    [adc10]
    [adc11]
    [adc12]
    [adc13]
    [tempc]
    [humid]

AVAILABLE PARAMETERS FOR 'LCDControl' METHOD:
    'mode_normal'  => '1',
    'mode_scroll'  => '2',
    'cursor_off'   => '3',
    'cursor_on'    => '4',
    'clrscr'       => '5',
    'monitor_off'  => '6',
    'monitor_POP3' => '7',
    'monitor_serv' => '8',
    'monitor_env'  => '9',
    'set_C'		   => 'A',
    'set_F'		   => 'B',    

AS A ADDITIONAL PARAMETER YOU MUUST USE DECIMAL VALUES:
LCDSetPosition("myfirst",1,5); col 5 not 05
PSet("myfirst",5,12); col 12 not 012
     
I ASSUME THAT $values['humid'] is a relative humidity (RH) THAN WE CAN CALCULATE DEW POINT:
     calculateDEWPoint(temp, humid)

---------------------------------------------------------------------------------------------
*/

#EXAMPLE 1: show values
echo "The temperature at Mirrorbow is ";
echo $values['tempc'];
echo "C and the relative humidity is ";
//echo "<br>";
echo $values['humid'];
echo "%";
echo "<br>";

#EXAMPLE 2: Basic LCD operations
/*
$mb_device->LCDControl("myfirst","monitor_off");
$mb_device->LCDControl("myfirst","clrscr");
$mb_device->LCDControl("myfirst","cursor_on");
$mb_device->LCDSetPosition("myfirst",1,5);
$mb_device->LCDText("myfirst","LCD DEVICE");
$mb_device->LCDControl("myfirst","cursor_off");
*/

#EXAMPLE 3: Your own value on the LCD display
/*
$mb_device->LCDControl("myfirst","monitor_off");
$mb_device->LCDControl("myfirst","clrscr");
$mb_device->LCDSetPosition("myfirst",2,0);
$dew_t = $mb_device->CalculateDEWPoint($values['tempc'], $values['humid']);
$dew_text= "DewP=" . $dew_t . "C";
$mb_device->LCDText("myfirst",$dew_text);
$mb_device->LCDControl("myfirst","monitor_env");
*/

#EXAMPLE 4: Ports
# for each port you want to set value for you need to set direction first:
# ALL bits in certain port must be oriented to output.
# single bits are not supported because it can't be red from device.
#?D1=000
#$mb_device->setPortDirection("livingroom",1,0);

$mb_device->setPortDirection("livingroom",1,0);

$binary_port_vlue = $mb_device->getPortValueToBin("livingroom", 1);
var_dump($binary_port_vlue);

$binary_port_vlue[0] = 0;
$binary_port_vlue[1] = 0;
$binary_port_vlue[2] = 0;
$binary_port_vlue[3] = 0;
$binary_port_vlue[4] = 1;

$binary_port_vlue[5] = 0;
$binary_port_vlue[6] = 0;
$binary_port_vlue[7] = 1;

$mb_device->setPortValueFromBin("livingroom",1,$binary_port_vlue);

$binary_port_vlue2 = $mb_device->getPortValueToBin("livingroom", 1);
var_dump($binary_port_vlue2);

#Set port5 decimal value to 44
#?P5=044
#$mb_device->setPortValue("myfirst",5,44);

#Set port5 direction to input
#?D5=001
#$mb_device->setPortDirection("myfirst",5,1);

#?ADC=0
#$mb_device->setADC("myfirst",0);

?>
